package org.luchengye.ioauth2.wwwclientserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.ProviderManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
public class OAuth2WWWClientApplication {
    public static void main(String[] args) {
        SpringApplication.run(OAuth2WWWClientApplication.class, args);
    }

//    public static void main(String[] args) {
//        UserDetailsService userDetailsService = new InMemoryUserDetailsManager();
//        AuthenticationProvider provider = new DaoAuthenticationProvider();
//        ((DaoAuthenticationProvider) provider).setUserDetailsService(userDetailsService);
//        ((DaoAuthenticationProvider) provider).setPasswordEncoder(new BCryptPasswordEncoder());
//
//        ((InMemoryUserDetailsManager) userDetailsService).createUser(User.withUsername("user").password(new BCryptPasswordEncoder().encode("password")).roles("USER").build());
//        Authentication authentication = new UsernamePasswordAuthenticationToken("user","password");
//
//        //验证方式1
//        //Authentication result = provider.authenticate(authentication);
//        //System.out.println(result);
//
//        //验证方式2
//        List<AuthenticationProvider> providers = new ArrayList<>();
//        providers.add(provider);
//        AuthenticationManager manager = new ProviderManager(providers);
//        Authentication result = manager.authenticate(authentication);
//        System.out.println(result);
//    }
}
